import * as THREE from 'three'
import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls'

let scene, cube, camera, renderer;
let axesHelper,controls

init();
render();

function init() {
  // 1. 创建场景
  scene = new THREE.Scene();
  
  // 创建立方体
  const geometry = new THREE.BoxGeometry(1, 1, 1);
  const material = new THREE.MeshBasicMaterial({ color: 0xffff00 });
  cube = new THREE.Mesh(geometry, material);
  scene.add(cube);
  axesHelper = new THREE.AxesHelper(3)
  scene.add(axesHelper)
  
  // 2. 创建相机
  camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
  camera.position.z = 10; // 修改相机位置
  
  // 3. 创建渲染器
  renderer = new THREE.WebGLRenderer();
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);
}
//4.添加控制器
controls = new OrbitControls(camera,renderer.domElement)
function render() {
  renderer.render(scene, camera);
  cube.rotation.y += 0.01
  requestAnimationFrame(render)
}
